import type{ IFormData } from './types';

export class ProductFormData implements IFormData {
  name: string = '';
  price: number = 0;
  stock: number = 0;
  thumbnail: string = '';
  code: string = '';
  category_id: string = '';
  description: string = '';
  images: string[] = [];
  videoUrl: string = '';
  sku: string = '';
  skus: string[] = [];
  slug: string = '';
  spec: string = '';
  status: string = 'draft'; // draft, published, archived
  weight: string = '';
  createTime: string = '';
  updateTime: string = '';

  constructor(data?: Partial<ProductFormData>) {
    this.reset();
    if (data) Object.assign(this, data);
  }

  reset(): void {
    Object.assign(this, {
      name: '',
      price: 0,
      stock: 0,
      thumbnail: '',
      code: '',
      category_id: '',
      description: '',
      images: [],
      videoUrl: '',
      sku: '',
      slug: '',
      spec: '',
      status: 'draft',
      weight: '',
      createTime: '',
      updateTime: ''

    });
  }

  toSubmitData() {
    return {
      name: this.name,
      price: this.price,
      stock: this.stock,
      thumbnail: this.thumbnail,
      images: this.images,
      videoUrl: this.videoUrl,
      code: this.code,
      category_id: this.category_id,
      description: this.description,
      slug: this.slug,
      sku: this.sku,
      spec: this.spec||'{}',
      status: this.status,
      weight: this.weight
    };
  }
}